<?php 
$this->breadcrumbs()->addPage('Abrir Processo', 'processos');
echo $this->breadcrumbs()->render(); 

echo $this->pagenav()->openList(); 
echo $this->pagenav()->defaultHelperLinks();
echo $this->pagenav()->closeList();
?>

<div id="article">
    <h4>1. Selecione o Tipo de Processo</h4>
    <form action="" method="post">
        <?php 
        echo $this->fieldList()->open();
        echo $this->fieldList()->select('Tipo de Processo',
                           'tipoprocesso',
                           $this->listaTiposProcesso,
                           null,
                           array('required' => true));
        ?>
        <dt style="width: 60%;">
            <a style="float: left;margin-top: 18px;" href="<?php echo $this->baseUrl()?>/docs/listagem.pdf" target="_blank">Listagem Tipos De Processo/Assuntos</a>
        </dt>
        <?php
        if (count($this->listaOrigens) > 1) {
            echo $this->fieldList()->select('Origem', 'origem', $this->listaOrigens, null, array('required' => true));
        } elseif (count($this->listaOrigens) == 1) {
            $keys = array_keys($this->listaOrigens);
            echo '<input type="hidden" name="origem" id="origem" value="' . $keys[0] . '" />';
        }
        
        echo $this->fieldList()->close();
        
        echo $this->buttonlist()->open();
        echo $this->buttonlist()->button('Avançar');
        echo $this->buttonlist()->close(true); 
        ?>
    </form>
</div>
<?php 
$js = '
    $(document).ready(function() {
        jQuery("#tipoprocesso").chosen();
        if ($("#origem option").size() > 0) {
            $("#origem").change(function() {
                $.ajax({
                dataType: "json",
                url:"' . $this->simpleUrl('listar-por-protocolo', 'tiposprocesso-ajax') . '/protocolo/" + $(this).val(),
                success: function(data) {
                    $("#tipoprocesso option").remove();
                    $(data).each(function(i, value) {
                        $("#tipoprocesso").append("<option value=\"" + value.id + "\">" + value.name + "</option>");
                    });
                }, 
                error: function(data) {
                    $("#tipoprocesso option").remove();
                }
            });
            });
        }
    });
';
$this->headScript()->appendScript($js, 'text/javascript');
?>